package com.batch.quartz.config;

import org.quartz.spi.TriggerFiredBundle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.scheduling.quartz.AdaptableJobFactory;

/**
 * <h3>partitionjob</h3>
 * <p>自动注入 工厂</p>
 *  这个类是用来为QuartzJob中的属性进行Spring IoC注入
 * @author : hduong
 * @version : 1.0
 * @date : 2019-12-19 17:32
 **/
public class AutowiringJobFactory extends AdaptableJobFactory {

    @Autowired
    private AutowireCapableBeanFactory autowireCapableBeanFactory;

    @Override
    protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {

        Object jobInstance = super.createJobInstance(bundle);
        //IOC 注入
        autowireCapableBeanFactory.autowireBean(jobInstance);
        return jobInstance;
    }
}
